package com.yzc.android.network.mock;

import android.content.Context;
import android.text.TextUtils;

/**
 * Created by yzc on 16/5/10.
 */
public class JsonFileResponse implements IFakeResponse {

    private String mFilePath;

    private AssetsFileParser mParser;

    public JsonFileResponse(final Context context, final String jsonFilePath) {
        if (TextUtils.isEmpty(jsonFilePath))
            return;
        mFilePath = jsonFilePath;
        mParser = new AssetsFileParser(context);
    }

    @Override
    public String body() {
        if (TextUtils.isEmpty(mFilePath))
            return "";
        String result = "";
        try {
            result = mParser.readJsonFile(mFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return result;
        }
    }

    @Override
    public String mediaType() {
        return "application/json";
    }

    @Override
    public int httpCode() {
        return 200;
    }
}
